function composeSystemMessage(
  programId: string,
  pageSize: number,
  startRow: number
) {
  // 定义SYS_HEAD
  const SYS_HEAD = {} as {
    TRAN_TIMESTAMP: number;
    PROGRAM_ID: string;
    TRAN_DATE: number;
  };
  SYS_HEAD.TRAN_TIMESTAMP = new Date().getTime();
  SYS_HEAD.PROGRAM_ID = programId;
  SYS_HEAD.TRAN_DATE = new Date().getTime();

  // 定义APP_HEAD
  const APP_HEAD = {} as {
    PAGE_SIZE: number;
    START_ROW: number;
    TOTAL_COUNT: number;
  };
  APP_HEAD.PAGE_SIZE = pageSize;
  APP_HEAD.START_ROW = startRow;
  APP_HEAD.TOTAL_COUNT = 0;

  return {
    SYS_HEAD: SYS_HEAD,
    APP_HEAD: APP_HEAD,
    MSG_BODY: {},
  };
}
interface Iresult {
  ok: boolean;
  message: string;
  retMessage: string;
  retCode: string;
  data: any;
  totalCount: number;
}
function processSystemMessage(response: any) {
  const result: Iresult = {
    ok: false,
    message: "",
    retMessage: "",
    retCode: "",
    data: {},
    totalCount: 0,
  };

  if (response.status !== 200) {
    result.ok = false;
    result.message = "HTTP error code:  " + response.status;
    result.data = response;
  }

  if (!response) {
    // no response
    result.ok = false;
    result.message = "Cannot Get Response!";
    result.data = response;
    return result;
  }

  if (!response.data.SYS_HEAD) {
    // no SYS_HEAD in response
    result.ok = false;
    result.message = "Cannot Get System Message Head Info!";
    result.data = response;
    return result;
  }

  // noinspection JSUnresolvedVariable
  if (!response.data.SYS_HEAD.RET) {
    // no RET info in SYS_HEAD
    result.ok = false;
    result.message = "Cannot Get System Message Head's RET Info!";
    result.data = response;
    return result;
  }

  // noinspection JSUnresolvedVariable
  if (response.data.SYS_HEAD.RET.RET_CODE !== "000000") {
    // RET_CODE doesn't equals code representing OK
    result.ok = false;
    // noinspection JSUnresolvedVariable
    result.message =
      "Error Code " +
      response.data.SYS_HEAD.RET.RET_CODE +
      ": " +
      response.data.SYS_HEAD.RET.RET_MSG;
    result.retMessage = response.data.SYS_HEAD.RET.RET_MSG;
    result.retCode = response.data.SYS_HEAD.RET.RET_CODE;
    result.data = response;
    return result;
  }

  if (!response.data) {
    // returning code representing ok but found no data
    result.ok = false;
    result.message = "Cannot Get Response's Data!";
    result.data = response;
    return result;
  }

  // everything is ok
  result.ok = true;
  // noinspection JSUnresolvedVariable
  result.message = response.data.SYS_HEAD.RET.RET_MSG;
  result.data = response.data.MSG_BODY;
  if (response.data.APP_HEAD && response.data.APP_HEAD.TOTAL_COUNT) {
    result.totalCount = response.data.APP_HEAD.TOTAL_COUNT;
  }
  return result;
}
export default {
  composeSystemMessage,
  processSystemMessage,
};
